import React, { Component } from 'react';
import PropTypes from 'prop-types'
import Comment from './Comment';

class CommentList extends Component {

    handleDeleteComment(index){
        if(this.props.onDeleteComment){
            this.props.onDeleteComment(index)
        }
    }
    render() {
        const { comments = [] } = this.props
        return (
            <div>
                {comments.map((comment, index) => {
                    return (<div key={index}>
                        <Comment comment={comment} key={index} index={index} onDeleteComment={this.handleDeleteComment.bind(this)}></Comment>
                    </div>)
                })}
            </div>

        )
    }
}
CommentList.propTypes={
    onDeleteComment:PropTypes.func.isRequired
}

export default CommentList